<?php
//include_once dirname(__FILE__).'/_config.php.';

list($frm, $fact) = explode('.', $_POST['formAction']);
$__arr = explode('_', $fact);
if(empty($__arr[1])){ // 动作不明确
	die('参数不全');
}
$goback = empty($_POST['goback']) ? 'back2edit' : trim($_POST['goback']);

$mdl = $__arr[0];
$do = $__arr[1]; // 动作类型
if(!empty($_POST['dos'])){
	if(is_array($_POST['dos'])){
		$do = array_pop(array_keys($_POST['dos']));
	}else{
		$do = trim($_POST['dos']);
	}
}
$result = -1;
$special = false;

$mdlfile = dirname(__FILE__).'/'.$mdl.'.action.php';
if(file_exists($mdlfile)){
	$special = true;
	include_once $mdlfile;
}

$clsname = ucwords($__arr[0]);
$clsfile = CLS_PTH."{$clsname}.class.php";
if(file_exists($clsfile)){
	include_once $clsfile;
	if(class_exists($clsname, false)){
		$obj = new $clsname(); // 类实例

		if(method_exists($obj, $do)){
			try{
				// $result = $obj->$do($_POST);	// debug_backtrace() 可以获取文件名＆所在行
				##^^ 使用 call_user_func_array()，debug_backtrace() 时无法获取文件名和所在行
				$result = call_user_func_array(array($obj, $do), array('post' => $_POST));
			}catch(Exception $e){
				die($e->getMessage());
			}
		}elseif(!$special){
			ajax_callback('error', "方法不存在：{$clsname}->{$do}()", $callback = 'callback_frlist', $synjs = '', $url = '', $ttl = 60000);
		}
	}else{
		ajax_callback('error', "类不存在：{$clsname}", $callback = 'callback_frlist', $synjs = '', $url = '', $ttl = 60000);
	}

}elseif(!$special){
	ajax_callback('error', "类文件不存在：{$clsfile}", $callback = 'callback_frlist', $synjs = '', $url = '', $ttl = 60000);
}

//goUrl($mdl, $do, $result, 'list');
$msg = array();
if(isset($__l["_mm_{$frm}_{$mdl}_list"])){
	$msg[] = $__l["_mm_{$frm}_{$mdl}_list"];
}elseif(isset($__l[$mdl])){
	$msg[] = $__l[$mdl];
}
$msg[] = '&nbsp;->&nbsp;';
if(isset($__l["_mp_{$frm}_{$mdl}_{$do}"])){
	$msg[] = $__l["_mp_{$frm}_{$mdl}_{$do}"];
}elseif(isset($__l[$do])){
	$msg[] = $__l[$do];
}

if(!empty($_POST['subAction'])){
	if(is_array($_POST['subAction'])){
		$subAction = array_pop(array_keys($_POST['subAction']));
	}else{
		$subAction = trim($_POST['subAction']);
	}
	$msg[] = '&nbsp;->&nbsp;';
	if(isset($__l["_mp_{$frm}_{$mdl}_{$subAction}"])){
		$msg[] = $__l["_mp_{$frm}_{$mdl}_{$subAction}"];
	}elseif(isset($__l[$subAction])){
		$msg[] = $__l[$subAction];
	}
}
$msg[] = '&nbsp;=&nbsp;';
$_result = false;
if(is_numeric($result) || is_bool($result)){
	if($result === true || $result > 0){
		$result = 'succ';
		$_result = true;
		$msg[] = $__l['success'];
	}elseif($result == 0){
		$msg[] = '无变化';
	}else{
		$msg[] = $__l['failure'];
	}
}elseif(is_array($result)){
	if($result['result'] == 'succ'){
		$_result = false;
		$msg[] = $__l['success'];
	}else{
		$msg[] = $__l['failure'];
	}
	if(!empty($result['rmsg'])){
		$msg[] = '，'.$result['rmsg'];
	}
	$result = $result['result'];
}else{
	$msg[] = $result;
}
$msg = implode("", $msg);
if($goback == 'frlist'){
	if($_result == true/*  && in_array($do, array('del', 'rank')) */){	// 需要自动刷新的情况
		$url = 'refresh';
	}
	ajax_callback($result, $msg, $callback = 'callback_frlist', $synjs = '', $url, $ttl = 60000);
}else{
	sysinfo($msg, $goback, 60000);
}
?>